10. Euler Rotations Exercise

Euler Rotations

The image above shows a vehicle mounted on three gimbals corresponding to roll (green), pitch (red) and yaw (blue). To get a better handle on gimbal lock and the ordering of Euler rotations, we built a handy little 3-axis gimbal simulator for you! If you're interested in playing with it, download the simulator appropriate for your operating system here.

The configuration shown above corresponds to Euler rotations in the following order where \phi denotes the roll angle about the x-axis, \theta denotes the pitch angle about the y-axis, and \psi the yaw angle about the z-axis:

R_z(\psi)R_y(\theta)R_x(\phi)= \begin{bmatrix} \rm{cos}\psi & -\rm{sin}\psi & 0 \\ \rm{sin}\psi & \rm{cos}\psi & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} \rm{cos}\theta &0 & \rm{sin}\theta \\ 0 & 1 & 0 \\ -\rm{sin}\theta & 0 & \rm{cos}\theta \end{bmatrix} \begin{bmatrix} 1 &0 & 0 \\ 0 &\rm{cos}\phi & -\rm{sin}\phi \\ 0 & \rm{sin}\phi & \rm{cos}\phi \end{bmatrix}

In this arrangement, the yaw rotation appears first, then pitch, then roll, which is the same way the gimbal apparatus shown above would function, with yaw as the outermost gimbal and roll on the inside. Rearranging the order of these matrix multiplications would be equivalent to rearranging the order of the gimbals above! Now we're going to dive right into coding it up, but for a delightfully thorough explanation of Euler rotations in all the gory details, check out this reference.

Euler Rotations Exercise

In this exercise, your task is to fill out the TODO's in the methods of the Rotation() class defined in the notebook below. Each of the roll(), pitch() and yaw() methods should return a rotation matrix corresponding to the appropriate Euler rotation, and the final method called rotate() should multiply them together and return the result.

Once you've got a working Rotation() class, you can test it out on different series of rotations to see how order of rotations makes a difference. Finally, you can demonstrate gimbal lock by first pitching the vehicle to +/- 90 degrees to find that yaw no longer has any effect!

Good luck! And for a look at our solution scroll down to the link at the bottom of the notebook.

Workspace

This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.

Workspace Information:

  • Default file path:
  • Workspace type: jupyter
  • Opened files (when workspace is loaded): n/a